<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>公海</title>
<style type="text/css">
	a{ text-decoration: none; }
	a:link { color: blue }               /* 未被访问的链接 */
	a:visited { color: blue }            /* 已被访问过的链接 */ 
</style>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.4.4.min.js"></script>
<script language=javascript>
	function pull(studentId){
		var sure = window.confirm("确定拉出公海吗？");
		if(sure){
			window.location.href="${pageContext.request.contextPath}/customer/pullCommon.action?studentId="+studentId;
		}
	};
	function goToPage(goPage){
		//因为js代码有要去的页码  可以在js中直接判断
		if(goPage<1){
			/* alert("当前已经是第一页了  不能上一页"); */
			return ; 
		}
		//获得最大页数
		var totalPage = '${pageBeanCommon.totalPage}';
		if(goPage>totalPage){ //当前页大于 最大页数
			/* alert("当前已经是最后一页了  不能下一页"); */
			return ; 
		}

		//函数的参数为 将要访问的页码 只需要条件 即可 
		//而条件在表单当中  我如果将页码也放入了表单  只需要提交表单 那条件有了 页码也有了
		//获得隐藏域 并且赋值即可
		$("#pageNumberId").val(goPage);
		//提交表单  先获得表单 再提交即可
		$("#commonForm").submit();
	};
	
	/*全选JS*/
    function CheckAll(thisform){
	    for (var i=0;i<thisform.elements.length;i++){
	    	var e = thisform.elements[i];
	    	if (e.Name != "chkAll"&&e.disabled!=true)
	    	e.checked = thisform.chkAll.checked;
	    }
    };
    
    function judgeCommon(){
	    var arrayid = new Array();
	    
	    $('input[name="ids"]:checked').each(function(){arrayid.push($(this).val());});
	    
	    if(arrayid.length==0){
		    alert("无学生选中！");
		    event.preventDefault(); // 兼容标准浏览器
		    window.event.returnValue = false; // 兼容IE6~8
	    }else if(arrayid.length > 0) {
	    	var msg = "您确定要将选中的学生拉出公海吗？";   
	        if (confirm(msg)==true){   
	            var allcheckbox = "";
	            var becheckbox = "";
	            $("input[name=ids]").each(function(){ //遍历table里的全部checkbox
	                allcheckbox += $(this).val() + ","; //获取所有checkbox的值
	                if($(this).attr("checked")) //如果被选中
	                    becheckbox += $(this).val() + ","; //获取被选中的值
	            });

	            if(becheckbox.length > 0) //如果获取到
	                becheckbox = becheckbox.substring(0, becheckbox.length - 1); //把最后一个逗号去掉
	                window.location = "${pageContext.request.contextPath}/customer/pullCommonAll.action?checkTnum="+becheckbox;
	        }
	    }
    };
</script>
</head>
<body>
	<h2>公&nbsp;&nbsp;&nbsp;海</h2>
	<s:form action="common" namespace="/customer" id="commonForm" name="commonForm">
		<p>公海人数：${pageBeanCommon.totalRecord}</p>
		<table cellSpacing=0 cellPadding=0 width="98%" border=0>
		<TBODY>
		<tr>
		<table borderColor=#cccccc cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
		<TBODY>
			<tr>
				<td height=25>
					<table cellSpacing=0 cellPadding=2 border=0>
						<TBODY>
							<tr>
								<td>学生查询：</td>
								<td>
									<s:textfield name="select" class="textbox" id="sChannel2" style="WIDTH: 80px" maxLength="50" />
								</td>
	
								<!-- 页码的隐藏域 -->
								<input type="hidden" name="pageNumber" value="1" id="pageNumberId"/>
								
								<td><s:submit value=" 筛选 "/></td>
								
								<td><input type="button" value="拉出公海" onclick="judgeCommon()" /></td>
							</tr>
						</TBODY>
					</table>
				</td>
			</tr>

			<tr>
				<td>
					<table >
					<TBODY>
						<tr style="FONT-WEIGHT: bold; FONT-STYLE: normal; BACKGROUND-COLOR: #eeeeee; TEXT-DECORATION: none">
							<td>选中<s:checkbox name="chkAll" onclick="CheckAll(this.form)" /></td>
							<td>学生ID</td>
							<td>学生姓名</td>
							<td>性别</td>
							<td>负责员工</td>
							<td>操作</td>
						</tr>
						
						<c:forEach items="${pageBeanCommon.data}" var="common">
						<tr style="FONT-WEIGHT: normal; FONT-STYLE: normal; BACKGROUND-COLOR: white; TEXT-DECORATION: none">
							
							<td>
								<%-- <s:checkbox name="ids" value="false" fieldValue="%{customer.studentId }" /> --%>
								<input name="ids" type="checkbox" value="${common.studentId }" />
							</td>
							<td>${common.studentId }</td>
							<td>${common.studentName }</td>
							<td>${common.studentSex ==0 ? "男" : "女"}</td>
							<td>${common.affiliatedTeacher.userName }</td>
							<td>
								<a href="javascript:pull('${common.studentId}')">拉出公海</a>
							</td>
						</tr>
						</c:forEach>
					</TBODY>
					</table>
				</td>
			</tr>
		</TBODY>
		</table>
		</tr>
		</TBODY>
		</table>
		<div style="height: 20px; text-align: right; margin-top:10px; font-size: 17px;" >
			共[<b>${pageBeanCommon.totalRecord}</b>]条记录&nbsp;,&nbsp;第[<b>${pageBeanCommon.pageNumber}</b>]页
			&nbsp;&nbsp;
			[<a href="javascript:void(0)" onclick="goToPage(${pageBeanCommon.pageNumber-1})">上一页</a>]
			<b>
				<%-- 前五后四动态条 前四后五动态条 其目的主要是保证数据一直在中间 不发生变化 --%>
				<c:forEach begin="${pageBeanCommon.start}" end="${pageBeanCommon.end}" step="1" var="numCommon">
					<a href="javascript:void(0)" onclick="goToPage(${numCommon})" >
						<font ${numCommon == pageBeanCommon.pageNumber ? "color='red'" : ""}>&nbsp;${numCommon}</font>
					</a>
				</c:forEach>
			</b>&nbsp;
			[<a href="javascript:void(0)" onclick="goToPage(${pageBeanCommon.pageNumber+1})">下一页</a>]
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		</div>				
	</s:form>
</body>
</html>